package com.nbjtjc.safe.service.edu;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduDailyNotifyMapper;
import com.nbjtjc.safe.model.edu.EduDailyNotify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EduDailyNotifyService {

	@Autowired
	EduDailyNotifyMapper eduDailyNotifyMapper;
	
	  public Result add(EduDailyNotify eduDailyNotify){
	        Result result=new Result();
	        if(ObjectUtil.isNull(eduDailyNotify)
	        		||ObjectUtil.isNull(eduDailyNotify.getInfoId())
	        		){
	            result.setFalse("日常培训信息表ID不能为空");
	            return result;
	        }

	        if(ObjectUtil.isNull(eduDailyNotify.getId())
	        		|| ObjectUtil.isNull(eduDailyNotifyMapper.selectByPrimaryKey(eduDailyNotify.getId()))){
	        	eduDailyNotify.setCancel(0);
	        	int res=eduDailyNotifyMapper.insertSelective(eduDailyNotify);
		            
		        if(res==0){
		            result.setFalse("插入失败");
		            return result;
	
		        }
		        }else
		        {
		        	int res=eduDailyNotifyMapper.updateByPrimaryKeySelective(eduDailyNotify);
		        	 if(res==0){
		        		 result.setFalse("更新失败");
				         return result;
	
		        	 }
		        }
	        result.setData(eduDailyNotify);
	        return result;
	    }



	public Result delete(EduDailyNotify eduDailyNotify){
	    Result result=new Result();
	    if(ObjectUtil.isNull(eduDailyNotify.getId())){
	        result.setFalse("删除对象不能为空");
	        return result;
	    }
	    int res=eduDailyNotifyMapper.cancelByPrimaryKey(eduDailyNotify.getId());
	    if(res==0){
	        result.setFalse("删除失败");
	        return result;
	        }
	    return result;
	}
	
	public Result delete(int id){
	    Result result=new Result();
	    if(ObjectUtil.isNull(id)){
	        result.setFalse("删除对象不能为空");
	        return result;
	    }
	    int res=eduDailyNotifyMapper.deleteByPrimaryKey(id);
	    if(res==0){
	        result.setFalse("删除失败");
	        return result;
	        }
	    return result;
	}
	
	//根据条件查找调查项目
	
	public Result find(EduDailyNotify eduDailyNotify) {
	    Result result = new Result();
	    PageHelper.startPage(eduDailyNotify.getPageCurrent(), eduDailyNotify.getPageSize());

	    List<EduDailyNotify> eduDailyNotifys = eduDailyNotifyMapper.select(eduDailyNotify);
	    result.setData(new PageInfo<>(eduDailyNotifys));
	
	    return result;
	}
}
